<?php
	require_once(dirname(__FILE__)."/../core/safeParam.php");
	
	class module
	{
		function Add($vars){
			global $database;
    		
    		if ($vars['delivery'] == '') {
    			$vars['delivery'] = 0;
    		}
    		
    		$vars['delivery_start'] = serialize($vars['delivery_start']);
    		$vars['delivery_end']   = serialize($vars['delivery_end']);
    		
    		if (trim($vars['password']) != ""){
    			// hash password, if it's supplied.  else just leave blank
	      	$vars['password'] = md5($vars['password']);
    		}
    		
    		$database->insert_array('locations', $vars);
    		header("Location: ../admin/index.php?edit=locations&updated=1");
  		}
  		
  		function Edit($vars){
    		global $database;
    		
    		if ($vars['delivery'] == '') {
    			$vars['delivery'] = 0;
    		}
    		
    		$vars['delivery_start'] = serialize($vars['delivery_start']);
    		$vars['delivery_end']   = serialize($vars['delivery_end']);
    		
    		if (trim($vars['password']) != ""){
    			// hash password, if it's supplied.  else remove from the update 
      		$vars['password'] = md5($vars['password']);
    		} else {
      		unset($vars['password']);
    		}
    		
    		$database->update_array('locations', $vars, "id = " . $vars['id'] . "");
    		header("Location: ../admin/index.php?edit=locations&updated=1");
  		}
  		
  		function Delete($vars){
    		global $database;
    		$database->delete('locations', "id = " . $vars['id'] . "");
    		header("Location: ../admin/index.php?edit=locations&updated=1");
  		}
  		
  		function DeleteZone($vars){
    		global $database;
    		$database->delete('locations_zone', "id = " . $vars['id'] . "");
    		header("Location: ../admin/index.php?edit=locations&lid=" . $vars['lid'] . "");
  		}
  		
  		function DeleteArea($vars){
    		global $database;
    		$database->delete('locations_zone_area', "id = " . $vars['id'] . "");
    		header("Location: ../admin/index.php?edit=locations&lid=" . $vars['lid'] . "");
  		}
  		
  		function AddZone($vars){
    		global $database;
    		$database->insert_array('locations_zone', $vars);
    		header("Location: ../admin/index.php?edit=locations&lid=" . $vars['lid'] . "");
  		}
  		
  		function AddZoneLoc($vars){
    		global $database;
    		$database->insert_array('locations_zone_area', $vars);
    		header("Location: ../admin/index.php?edit=locations&lid=" . $vars['lid'] . "");
  		}
}

?>
